<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Widget Platform</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <div class="background-blur"></div>
    
    <div class="container">
        <!-- Header -->
        <header class="header">
            <div class="header-content">
                <div class="logo">
                    <i class="fas fa-cube"></i>
                    <span>Widget Platform</span>
                </div>
                <div class="header-actions">
                    <div class="user-info" id="userInfo" style="display: none;">
                        <span class="username" id="username"></span>
                        <button class="user-menu-btn" onclick="toggleUserMenu()">
                            <i class="fas fa-user-circle"></i>
                        </button>
                        <div class="user-menu" id="userMenu">
                            <button onclick="logout()" class="logout-btn">
                                <i class="fas fa-sign-out-alt"></i>
                                <span data-i18n="auth.logout">Logout</span>
                            </button>
                        </div>
                    </div>
                    <button class="login-btn" id="loginBtn" onclick="showLoginModal()">
                        <i class="fas fa-sign-in-alt"></i>
                        <span data-i18n="auth.login">Login</span>
                    </button>
                    <div class="language-selector">
                        <select id="languageSelect" onchange="changeLanguage(this.value)">
                            <option value="en">English</option>
                            <option value="zh">中文</option>
                        </select>
                    </div>
                    <button class="add-widget-btn" id="addWidgetBtn" onclick="toggleWidgetPanel()" style="display: none;">
                        <i class="fas fa-plus"></i>
                        <span data-i18n="app.addWidget">Add Widget</span>
                    </button>
                </div>
            </div>
        </header>

        <!-- Widget Panel -->
        <div class="widget-panel" id="widgetPanel">
            <div class="panel-header">
                <h3>Add New Widget</h3>
                <button class="close-btn" onclick="toggleWidgetPanel()">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="panel-content">
                <div class="widget-types" id="widgetTypes">
                    <!-- Widget types will be dynamically loaded here -->
                </div>
                <div class="config-section" id="configSection" style="display: none;">
                    <h4>Configuration</h4>
                    <div class="config-help" id="configHelp">
                        <!-- Configuration examples will be loaded here -->
                    </div>
                    <textarea id="widgetConfig" placeholder='Enter JSON configuration (optional)' rows="6"></textarea>
                    <button class="create-btn" onclick="createSelectedWidget()">
                        <i class="fas fa-plus"></i>
                        Create Widget
                    </button>
                </div>
            </div>
        </div>

        <!-- Main Grid -->
        <main class="main-grid" id="mainGrid">
            <div class="empty-state">
                <i class="fas fa-cube"></i>
                <h2 data-i18n="app.noWidgets">No widgets yet</h2>
                <p data-i18n="app.clickToAddWidget">Click "Add Widget" to get started</p>
                <button class="add-widget-btn" onclick="toggleWidgetPanel()">
                    <i class="fas fa-plus"></i>
                    <span data-i18n="app.addFirstWidget">Add Your First Widget</span>
                </button>
            </div>
        </main>
    </div>

    <div class="overlay" id="overlay"></div>

    <!-- Login Modal -->
    <div class="modal" id="loginModal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 data-i18n="auth.login">Login</h3>
                <button class="close-btn" onclick="hideLoginModal()">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="modal-body">
                <form id="loginForm" onsubmit="handleLogin(event)">
                    <div class="form-group">
                        <label for="loginUsername" data-i18n="auth.username">Username</label>
                        <input type="text" id="loginUsername" required>
                    </div>
                    <div class="form-group">
                        <label for="loginPassword" data-i18n="auth.password">Password</label>
                        <input type="password" id="loginPassword" required>
                    </div>
                    <button type="submit" class="login-submit-btn">
                        <i class="fas fa-sign-in-alt"></i>
                        <span data-i18n="auth.login">Login</span>
                    </button>
                </form>
                <div class="login-info">
                    <p><strong>Default Admin:</strong> admin / admin123</p>
                </div>
            </div>
        </div>
    </div>

    <!-- User Management Modal (Admin Only) -->
    <div class="modal" id="userManagementModal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 data-i18n="admin.userManagement">User Management</h3>
                <button class="close-btn" onclick="hideUserManagementModal()">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="modal-body">
                <div class="admin-actions">
                    <button class="add-user-btn" onclick="showAddUserForm()">
                        <i class="fas fa-user-plus"></i>
                        <span data-i18n="admin.addUser">Add User</span>
                    </button>
                </div>
                <div class="user-list" id="userList">
                    <!-- Users will be loaded here -->
                </div>
                <div class="add-user-form" id="addUserForm" style="display: none;">
                    <h4 data-i18n="admin.addNewUser">Add New User</h4>
                    <form id="addUserFormElement" onsubmit="handleAddUser(event)">
                        <div class="form-group">
                            <label for="newUsername" data-i18n="auth.username">Username</label>
                            <input type="text" id="newUsername" required>
                        </div>
                        <div class="form-group">
                            <label for="newPassword" data-i18n="auth.password">Password</label>
                            <input type="password" id="newPassword" required>
                        </div>
                        <div class="form-group">
                            <label for="newUserRole" data-i18n="auth.role">Role</label>
                            <select id="newUserRole">
                                <option value="user">User</option>
                                <option value="admin">Admin</option>
                            </select>
                        </div>
                        <div class="form-actions">
                            <button type="submit" class="submit-btn">
                                <i class="fas fa-plus"></i>
                                <span data-i18n="admin.addUser">Add User</span>
                            </button>
                            <button type="button" class="cancel-btn" onclick="hideAddUserForm()">
                                <span data-i18n="common.cancel">Cancel</span>
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="app.js"></script>
</body>
</html>